package com.qigao.mall.web.controller.app.user;

import com.qigao.mall.api.ItemCatService;
import com.qigao.mall.commons.dto.ItemCatResultDto;
import com.qigao.mall.commons.enums.Result;
import com.qigao.mall.commons.enums.ResultCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/app/user/itemCat")
@Api(tags = "App商品分类相关API",value = "App商品分类相关API")
public class AppItemCatController {

    private static Logger logger= LoggerFactory.getLogger(AppItemCatController.class);
    @Resource
    ItemCatService itemCatService;

    //1.获取某个店铺所有商品分类
    @GetMapping("/findAll/{shopNo}")
    @ApiOperation(value = "获取某个店铺所有商品分类", notes = "获取某个店铺所有商品分类")
    public Result<List<ItemCatResultDto>> findAll(@PathVariable("shopNo")String shopNo){
        try{
            return itemCatService.findAll(shopNo);
        }catch (Exception e){
            logger.error("[获取所有商品分类]发生异常:{}",e);
            return Result.newError(ResultCode.FAIL);
        }
    }



    //2.获取某个店铺的所有一级商品分类
    @GetMapping("/findItemCat/{shopNo}")
    @ApiOperation(value = "获取某个店铺的所有一级商品分类", notes = "获取某个店铺的所有一级商品分类")
    public Result<List<ItemCatResultDto>> findItemCat(@PathVariable("shopNo")String shopNo){
        try{
            return itemCatService.findItemCatLevelOne(shopNo);
        }catch (Exception e){
            logger.error("[商品分类]发生异常:{}",e);
            return Result.newError(ResultCode.FAIL);
        }
    }

    /**
     * 获取下级分类目录
     * @return
     */
    @GetMapping("/findChildItemCatByNo")
    @ApiOperation(value = "获取下级分类目录", notes = "获取下级分类目录")
    public Result<List<ItemCatResultDto>> findChildItemCatByNo(@RequestParam("catNo")String catNo){
        try{
            return itemCatService.findChildItemCatByNo(catNo);
        }catch (Exception e){
            logger.error("[商品分类]发生异常:{}",e);
            return Result.newError(ResultCode.FAIL);
        }
    }


}
